using System;
using FytSoa.Common;
using Newtonsoft.Json;

namespace FytSoa.Extensions.Xcx
{
    public class XcxHelper
    {
        public static WxSession Code2Session(string code)
        {
            var url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + XcxPayConfig.APPID + "&secret=" + XcxPayConfig.APPSECRET + "&js_code=" + code + "&grant_type=authorization_code";
            Logger.Default.Debug(url);
            try
            {
                var res = HttpHelper.HttpGet(url);
                Logger.Default.Debug("openid："+res);
                return JsonConvert.DeserializeObject<WxSession>(res);
            }
            catch (Exception)
            {
                return null;
            }
        }
    }
    public class WxSession
    {
        public string openid { get; set; }
        public string session_key { get; set; }
        public string errcode { get; set; }
        public string errMsg { get; set; }
        public string unionid { get; set; }
    }
}
